package com.laivi.basic.module.syncdata;

import java.util.TimerTask;

import com.laivi.basic.module.log.Log;
import com.laivi.basic.module.log.Logs;
import com.laivi.basic.type.Status;

public abstract class Task extends TimerTask{
	protected Log log=Logs.getLog(Task.class);
	
	protected String name;         	//任务名称
	protected long period;			//任务周期，0表示只执行一次
	protected Status status;
	
	public Task(){
	}
	
	public Task(String name) {
		super();
		this.name = name;
	}
	
	public Task(String name, long period) {
		super();
		this.name = name;
		this.period = period;
	}

	@Override
	public void run() {
		try {
			execute();
		} catch (Exception e) {
			log.error(this.getName()+" task execute error:"+e.getMessage());
		}
	}
	
	public void stop(){
		this.cancel();
		this.status=Status.STOP;
	}
	
	abstract public void execute()throws Exception;

	public long getPeriod() {
		return period;
	}

	public String getName() {
		return name;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}
}
